<%--                                                                       --%>
<%-- Copyright (c) 2002-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<bean:define id="micrositeNaviInfoParams" name="micrositeNaviInfoView" property="urlParams" scope="request" />

<script language="javascript">
<!--

// Gets user's confirmation to delete the checklist
function confirmDeleteChecklist(theForm, url) {
  if (confirm('<bean:message key="cs.checklist.confirmDelete"/>')) {
    theForm.action = url;
    theForm.submit();
  }
  else {
    return false;
  }  
}

function onClickButton(theForm, url) {
  theForm.action = url;
  theForm.submit();
}

// validate form before save
function onClickSave(form) {
  if (validateForm(form)) {
    form.submit();
  }
}

// Add a function called trim as a method of the prototype 
// object of the String constructor.
String.prototype.trim = function() {
  // Use a regular expression to replace leading and trailing 
  // spaces with the empty string
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

//
// Validate the user's entries.
//
function validateForm(form) {  
  form.name.value = form.name.value.trim();
  if (form.name.value== "") {
      alert('<bean:message key="cs.checklist.error.name"/>');
      return false;
  }

  var desc = form.description.value.trim();
  form.description.value = desc;
  if (desc.length > 2000) {
      alert('<bean:message key="cs.checklist.error.description"/>');
      return false;
  }

  if (form.groupIds.selectedIndex == -1) {
      alert('<bean:message key="cs.checklist.error.group"/>');
      return false; 
  }

  var selectedOwner = document.csChecklistEditForm.ownerId.value;

  if (selectedOwner == -1) {
      alert('<bean:message key="cs.checklist.error.owner"/>');
      return false; 
  }

  return true;
}

// Check if an array contains the specific item
function arrayContainsItem(array, item) {
   var len_array = array.length;
   var i_array;

   for (i_array = 0; i_array < len_array; i_array++)
   {
      if (array[i_array] == item)
      {
         return true;
      }
   }

   return false;
}


//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   


function selectOwnerPopup(theForm) {
  var groupIndex = document.csChecklistEditForm.groupIds.selectedIndex;

  if (groupIndex == -1) {
    alert("<bean:message key="cs.checklist.error.group"/>");
    return false;	
  }   

  var popupURL = '<html:rewrite page="/cs/contentSelectOwner.do" name="micrositeNaviInfoParams" />';
  var timestamp = getTimeStamp();
  popupURL += '&timestamp=' + timestamp;

  var win = window.open('', "ContentSelectOwner", "width=500,height=400,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
  // save the current form setting so that it can be restored later
  var oldAction = theForm.action;
  var oldTarget = theForm.target;
  // submit the form to the popup so that we can pass the groupIds to the popup
  theForm.action = popupURL;
  theForm.target = "ContentSelectOwner";   
  theForm.submit();
  theForm.action = oldAction;
  theForm.target = oldTarget;
}

function setOwner(selectedOwnerId, selectedOwnerName) {
  document.csChecklistEditForm.ownerId.value = selectedOwnerId;
  document.csChecklistEditForm.ownerName.value = selectedOwnerName;

}

function resetOwner(selectedOwnerId, selectedOwnerName) {
  document.csChecklistEditForm.ownerId.value = -1;
  document.csChecklistEditForm.ownerName.value = "";

}

// -->
</script>

<!-- Zone 5 starts here.  -->

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->

    <html:form action="/cs/checklistSave.do" method="post" onsubmit="return false;">
    <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
    <input type="hidden" name="sequenceKey" value=<bean:write name="csChecklistEditForm" property="sequenceKey" /> >
    <input type="hidden" name="parentContentType" value="331">
    <input type="hidden" name="markAction" value=""> 
    <input type="hidden" name="fromPage" value=""> 
  
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:write name="checklistEditView" property="pageTitle"/>
      </span>
      <span class="right">
          <logic:notEqual name="csChecklistEditForm" property="checklistId" value="0">
            <input type="button" class="titleButton" name="deleteBtn"
               titleKey="button.delete" 
               value='<bean:message key="button.delete"/>'
               onclick="confirmDeleteChecklist(this.form, '<html:rewrite page="/cs/checklistDelete.do"/>')">
          </logic:notEqual>
      </span>
    </div> 
    <!--end title bar here--> 
    
    <div class="blockWrap">
    
    <!-- start Page Instructions -->
    <div class="pageInstructions">
        <logic:equal name="csChecklistEditForm" property="checklistId" value="0">
          <bean:message key="cs.checklist.new.instruction"/>
        </logic:equal>
        <logic:notEqual name="csChecklistEditForm" property="checklistId" value="0">
          <bean:message key="cs.checklist.edit.instruction"/>
        </logic:notEqual>
    </div>
    <!-- End Page Instructions -->
    
    <!--start main content area here-->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Checklist Information">
             
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.checklist.name"/>*: </td>
        <td width="80%" nowrap class="labelField"> 
          <html:text property="name" size="50" maxlength="80"/>
        </td>
      </tr>
    
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.description"/>: </td>
        <td width="80%" nowrap class="labelField"> 
          <html:textarea property="description" cols="50" rows="5"/>
        </td>
      </tr>
      
      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="true">
      <bean:define id="allPhasesList" name="checklistEditView" property="allPhasesList" />
        <tr> 
          <td nowrap width="20%" class="label"><bean:message key="cs.phase"/>*:</td>
          <td width="80%" nowrap class="labelField"> 
            <html:select property="newPhaseId" size="1">
              <html:options name="checklistEditView" collection="allPhasesList" property="id" labelProperty="name" />
            </html:select>
          </td>
        </tr>
      </logic:equal>
      
      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="false">
       <html:hidden property="phaseId"/>
      </logic:equal>
 
       
      <tr> 
        <td class="label" nowrap width="20%">
          <bean:message key="cs.read.access.groups"/>*:<br>
        </td>
        <td width="80%" nowrap class="labelField"> 
            <bean:define id="availableGroups" name="checklistEditView" property="availableGroups" />
            <html:select property="groupIds" size="4" multiple="true" onchange="resetOwner()">
              <html:optionsCollection  name="checklistEditView" property="availableGroups"/>
            </html:select>
        </td>
      </tr>
      <tr> 
        <td class="label" nowrap width="20%" ><bean:message key="cs.owner"/>*:</td>
        <td width="80%" nowrap class="labelField"> 
          <html:text name="csChecklistEditForm" property="ownerName" readonly="true"/>
          <input type="hidden" name="ownerId" value=<bean:write name="csChecklistEditForm" property="ownerId"/> >
          <html:button property="selectOwner" onclick="selectOwnerPopup(this.form)" styleClass="inputButton">
            <bean:message key="cs.button.select.owner"/>
          </html:button>
        </td>
      </tr>
      
    </table>
<!--start cancel, reset, save bar area here-->

    <div class="pageButtonWrap" align="right">
      <logic:equal name="csChecklistEditForm" property="checklistId" value="0">
        <input type="button" class="pageButton" name="resetBtn"
               value='<bean:message key="button.reset"/>'
               titleKey="button.reset"
               onclick="onClickButton(this.form, '<html:rewrite page="/cs/checklistNew.do"/>')">  
      </logic:equal>
      <logic:notEqual name="csChecklistEditForm" property="checklistId" value="0">
      <input type="button" class="pageButton" name="resetBtn"
             value='<bean:message key="button.reset"/>'
             titleKey="button.reset"
             onclick="onClickButton(this.form, '<html:rewrite page="/cs/checklistEdit.do"/>')">  
      </logic:notEqual>
	&nbsp;&nbsp;      
      <input type="button" class="pageButton" name="cancelBtn"
             value='<bean:message key="button.cancel"/>'
             titleKey="button.cancel"
             onclick="onClickButton(this.form, '<html:rewrite page="/cs/checklistList.do"/>')">
      
      
      <input type="button"  class="pageButton" name="saveBtn"
             titleKey="button.save" onclick="onClickSave(this.form)"
             value='<bean:message key="button.save"/>'>
             
    </div>          
    <!--end cancel, reset, save bar area here-->
    </html:form>
    
    </div> <!-- end of blockWrap -->
    </td>
  </tr>
</table>
<!--end zone 5 content here -->
     
